﻿using AiQiuQuan.Sport.Model.Enums;
using System.ComponentModel.DataAnnotations;

namespace AiQiuQuan.Sport.Model.Models
{
    /// <summary>
    /// 支付请求
    /// </summary>
    public class PayRequestDto : IValidatableObject
    {
        /// <summary>
        /// 当前用户ID
        /// </summary>
        public Guid UserId { get; set; }

        /// <summary>
        /// 业务类型：1场馆场地订单、5活动订单、10比赛订单
        /// </summary>
        [Required(ErrorMessage = "业务类型必填：1场馆场地订单、5活动订单、10比赛订单")]
        public BusinessTypeEnum BusinessType { get; set; }

        /// <summary>
        /// 支付方式：1.微信支付、2支付宝支付、3.场馆会员卡支付
        /// </summary>
        [Required]
        [EnumDataType(typeof(PayTypeEnum), ErrorMessage = "支付方式：1.微信支付、3.场馆会员卡支付")]
        public PayTypeEnum PayType { get; set; }

        /// <summary>
        /// 终端类型：1 小程序、2 H5、3 APP
        /// </summary>
        public ClientTypeEnum ClientType { get; set; } = ClientTypeEnum.MiniProgram;

        /// <summary>
        /// 业务订单ID
        /// </summary>
        [Required(ErrorMessage = "业务订单必填")]
        public Guid OrderId { get; set; }

        /// <summary>
        /// 线上支付金额
        /// </summary>
        [Required]
        public decimal PayAmount { get; set; }

        /// <summary>
        /// 现金
        /// </summary>
        public decimal CashAmount { get; set; }

        /// <summary>
        /// 补偿金额，可正可负(按需填写)
        /// </summary>
        public decimal CompensationAmount { get; set; }

        /// <summary>
        /// 场馆用户会员卡ID
        /// </summary>
        public Guid? VenueUserCardId { get; set; }

        /// <summary>
        /// validate
        /// </summary>
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (OrderId == default)
            {
                yield return new ValidationResult("业务订单id错误");
                yield break;
            }

            if (PayAmount < 0)
            {
                yield return new ValidationResult("支付金额小于0");
                yield break;
            }

            if (CashAmount < 0)
            {
                yield return new ValidationResult("现金小于0");
                yield break;
            }
        }
    }
}
